﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EasyTest.Logger {
        
    public class EasyTestLogger {
        static LoggingEngine _le = new LoggingEngine(new FileLogger());
        public static string TestName = "";
        public static void Log(string msg) {
            
            var methodInfo = new StackFrame(4).GetMethod();

            Log(methodInfo.DeclaringType.Name, methodInfo.Name, msg);

        }
        public static void LogTestName()
        {
            if (Browser.TestContext != null)
            {
                if (Browser.TestContext.TestName != TestName)
                {
                    TestName = Browser.TestContext.TestName;
                    string testInfo = String.Format(Environment.NewLine+"############# Test Class: {0}  Test Name: {1} #######################",
                                                    Browser.TestContext.FullyQualifiedTestClassName, Browser.TestContext.TestName);
                    _le.Log(testInfo);
                }
            }
            
        }
        public static void Log(string className, string methodName, string msg) {
            LogTestName();
            _le.Log(string.Format("{0:MM/dd/yyyy hh:mm:ss} {1}.{2}() - {3}", DateTime.Now, className, methodName, msg));

        }
        
    }
}
